package com.example.HelloSpace.worker;

import android.content.Context;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import com.example.HelloSpace.AlarmActivity;
import com.example.HelloSpace.service.AlarmService;
import com.example.HelloSpace.utils.NotificationHelper;

public class SendMessageWorker extends Worker {
    public SendMessageWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
        super(context, workerParams);
    }

    @NonNull
    @Override
    public Result doWork() {
        //Log.d("YourWorker", "Worker task started");
        // 调用通知帮助类来显示通知
//        NotificationHelper.showFullScreenNotification(getApplicationContext(),
//                1,
//                "消息标题",
//                "消息内容");

        Context context = getApplicationContext();
        Intent serviceIntent = new Intent(context, AlarmService.class);
        // 根据服务的实际需求设置类型
        //serviceIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        //        context.startForegroundService(serviceIntent);
//        Log.d("YourWorker", "Worker task started");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            context.startForegroundService(serviceIntent);
            Log.d("YourWorker", "Worker task started");
        } else {
            context.startService(serviceIntent);
        }

        return Result.success();
    }
}
